package cn.sxgan.common.config;


import cn.sxgan.common.interceptor.AllRequestInterceptor;
import cn.sxgan.common.interceptor.AuthInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 全局请求路径拦截器
 * @Author: sxgan
 * @Date: 24/7/12 17:33
 * @Version: 1.0
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    private static final List<String> WHITE_LIST = new ArrayList<>();
    
    static {
        WHITE_LIST.add("/v3/api-docs");
        WHITE_LIST.add("/auth/signin");
        WHITE_LIST.add("/auth/signup");
        WHITE_LIST.add("/auth/verifyCodeImg");
        WHITE_LIST.add("/auth/mailVerifyCode");
        WHITE_LIST.add("/file/singleFileUpload");
        WHITE_LIST.add("/file/multipleFilesUpload");
    }
    
    /**
     * 添加自定义拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AllRequestInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/v3/api-docs");
        registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(WHITE_LIST);
    }
}